package org.nf.web.view;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletResponse;
import org.nf.web.servlet.ServletApi;
import org.nf.web.servlet.View;

import java.io.IOException;

/**
 * @Author lzp
 * @Date 2024-05-20
 * 默认视图处理,处理非View接口的视图对象
 */
public class DefaultView implements View {

    private final Object obj;

    public DefaultView(Object obj) {
        this.obj = obj;
    }


    @Override
    public void render(ServletApi api) throws ServletException, IOException {
        HttpServletResponse response = api.response();
        response.setContentType("text/plain;charset=utf-8");
        response.getWriter().println(obj);
    }
}
